package com.demo.coroutinedemo1

import android.util.Log
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.cancel
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

/**
 * Created by zhangyuncai on 2025/1/17.
 * 描述：
 */
class MainVM : ViewModel() {
    val nameLive=MutableLiveData<String>()
    fun getUserName() {
        viewModelScope.launch {
            delay(5000)
            Log.e("MainVM","test:${Thread.currentThread().name}")
            nameLive.value="getUserName"
        }
    }

    override fun onCleared() {
        super.onCleared()
        viewModelScope.cancel()

    }
}